package io.coderyeah.basic;

import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 封装结果集
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("统一封装返回结果集")
public class Result {
    //请求是否成功
    private Boolean success;
    //返回信息
    private String msg;
    //数据
    private Object data;
    //查询总数
    private Long totals;

    public Result(boolean success, String msg) {
        this.success = success;
        this.msg = msg;
    }

    public Result(boolean success, Object data) {
        this.success = success;
        this.data = data;
    }

    public Result(boolean success, String msg, Object data) {
        this.success = success;
        this.msg = msg;
        this.data = data;
    }

    public static Result success(Object data, Long totals) {
        return new Result(true, null, data, totals);
    }

    public static Result success(Object data, String msg, Long totals) {
        return new Result(true, msg, data, totals);
    }

    public static Result success(String msg) {
        return new Result(true, msg);
    }

    public static Result success(Object data) {
        return new Result(true, null, data);
    }

    public static Result fail(String msg) {
        return new Result(false, msg);
    }

    public static Result fail(Object data) {
        return new Result(false, data);
    }
}
